<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="author" content="VectorX">
    <meta name="keywords" content="固定定位">
    <title>固定定位</title>
    <style>
        body {
            height: 1000px;
        }

        div {
            font-size: 50px;
        }

        .box1 {
            width: 200px;
            height: 200px;
            background-color: #bfa;
        }

        .box2 {
            width: 400px;
            height: 400px;
            background-color: tomato;
            /* 开启相对定位 */
            /* position: relative; */
        }

        .box3 {
            width: 300px;
            height: 300px;
            background-color: aliceblue;
            /* 开启相对定位 */
            /* position: relative; */
        }

        .box4 {
            width: 200px;
            height: 200px;
            background-color: yellow;
            /* 开启固定定位 */
            position: fixed;
            /* 开启绝对定位 */
            /* position: absolute; */
            /* top: 0;
            left: 0; */
        }

        .box5 {
            width: 200px;
            height: 200px;
            background-color: orange;
        }
    </style>
</head>

<body>
    <div class="box1">1</div>
    <div class="box2">2
        <div class="box3">3
            <div class="box4">4</div>
        </div>
    </div>
    <div class="box5">5</div>
</body>

</html>